package com.example.task;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Component
@Aspect
public class ScheduledAnnotationAopService {

    @Pointcut("@annotation(org.springframework.scheduling.annotation.Scheduled)")
    public void catScheduled() {}

    @Around("catScheduled()")
    public void aroundMethod(ProceedingJoinPoint pjp) throws Throwable {
        MethodSignature signature = (MethodSignature) pjp.getSignature();
        Method method = signature.getMethod();

        String methodName = method.getDeclaringClass().getName() + "." + method.getName();

        System.out.println("==================ScheduledAnnotationAopService =================== begin ----------methodName: " + methodName);
        pjp.proceed();
        System.out.println("==================ScheduledAnnotationAopService =================== end ----------methodName: " + methodName);
    }

}
